Skip to content
This repository has been archived by the owner on Jun 27, 2023. It is now read-only.

decouple the DAG traversal logic from the DAG reader #12

Closed
wants to merge 3 commits into from
Closed

decouple the DAG traversal logic from the DAG reader #12

wants to merge 3 commits into from

Conversation

schomatis
Copy link
Contributor

@schomatis schomatis commented Aug 27, 2018

unixfs: decouple the DAG traversal logic from the DAG reader

Decouple the DAG traversal logic from the `PBDagReader` encapsulating it in the
(new) `Walker` structure.

Collapse PB and Buffer DAG readers into one (`dagReader`) removing the
`bufdagreader.go` and `pbdagreader.go` files, moving all the code to
`dagreader.go`.

Remove `TestSeekAndReadLarge` and `TestReadAndCancel` which operated directly on
the `NodePromise` structure that is now abstracted away in `NavigableIPLDNode`,
in the `go-ipld-format` repo, where they should be recreated.

Imported from ipfs/kubo#5257.

Based on #58 (should be merged first).

Fixes #14.
Fixes ipfs/kubo#5255.
Closes ipfs/kubo#5192.

TODO:

  • Use the new go-ipld-format release with the Walker
  • Commit message
  • Evaluate improving the WriteTo method now in this PR, the previous (PBDagReader) implementation was more performant (this doesn't block the review of the rest of the PR).
  • Port TestSeekAndReadLarge and TestReadAndCancel to go-ipld-format

@schomatis
Copy link
Contributor Author

With ipfs/go-ipld-format#39 merged this is now unblocked, I'll give it the finishing touches and get it ready for review next week.

@schomatis
Copy link
Contributor Author

schomatis commented Dec 3, 2018

@Stebalien There are some particulars pending but we can start the review process of this PR now, feel free to delegate the review to whomever you see fit.

(edit: @warpfork might be the best choice here since he's already familiar with the Walker)

@schomatis
Copy link
Contributor Author

/cc @warpfork

@schomatis
Copy link
Contributor Author

@Stebalien This doesn't have a high priority but it's part of one of my Q4 OKRs, if @warpfork is busy at the moment is there anyone else who could help with the review? Basically what I need at this point is not an exhaustive review but just a check to see if this PR makes sense or not to help me plan how minor or major it will be the work needed to eventually make it land.

@Stebalien
Copy link
Member

I'll bring it up at the meeting tomorrow. Could you put it in the notes: ipfs/team-mgmt#674 (comment)?

@magik6k magik6k self-requested a review December 17, 2018 18:07
Copy link
Member

@magik6k magik6k left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, 1 question.

io/dagreader.go Show resolved Hide resolved
@schomatis
Copy link
Contributor Author

Thanks for taking a look @magik6k! ❤️

@ghost ghost assigned Stebalien Jan 9, 2019
@eingenito
Copy link

@schomatis Is this awaiting further review?

@schomatis
Copy link
Contributor Author

No, thanks for the ping, I'll act on this during this week (and then I'll probably need a final review).

Decouple the DAG traversal logic from the `PBDagReader` encapsulating it in the
(new) `Walker` structure.

Collapse PB and Buffer DAG readers into one (`dagReader`) removing the
`bufdagreader.go` and `pbdagreader.go` files, moving all the code to
`dagreader.go`.

Remove `TestSeekAndReadLarge` and `TestReadAndCancel` which operated directly on
the `NodePromise` structure that is now abstracted away in `NavigableIPLDNode`,
in the `go-ipld-format` repo, where they should be recreated.

License: MIT
Signed-off-by: Lucas Molas <schomatis@gmail.com>
This version writes one node at a time instead of first buffering the entire
file contents in a single array (taking up too much memory) before actually
writing it.
@schomatis schomatis changed the title [WIP] decouple the DAG traversal logic from the DAG reader decouple the DAG traversal logic from the DAG reader Jan 18, 2019
@schomatis
Copy link
Contributor Author

@magik6k Can I bother you to check the last commit that completes this PR before I merge it please?

@schomatis schomatis added status/in-progress In progress and removed status/in-progress In progress labels Jan 18, 2019
@magik6k magik6k self-requested a review January 19, 2019 17:54

// Skip internal nodes, they shouldn't have any file data
// (see the `balanced` package for more details).
if len(node.Links()) > 0 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably check for data and return errors / warnings if preset.

})

if err == ipld.EndOfDag {
return n, io.EOF
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at impl of bytes.Reader.WriteTo, error should be nil here - https://golang.org/src/bytes/reader.go?s=3220:3278#L124

// searches in the `Walker` (see `Walker.Seek`).

case io.SeekEnd:
return dr.Seek(int64(dr.Size())-offset, io.SeekStart)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return dr.Seek(int64(dr.Size())-offset, io.SeekStart)
return dr.Seek(int64(dr.Size())+offset, io.SeekStart)

This is also a bug in current implementation - https://golang.org/pkg/io/#Seeker - https://golang.org/src/bytes/reader.go?s=2744:2806#L103 - ipfs/kubo#5934

Copy link
Member

@Stebalien Stebalien left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's always nice when the SLOC goes down but the number of lines in a package goes up.

(I'll defer to @magik6k for an actual review/signoff).

return err
}

_, err = dr.currentNodeData.Seek(left, io.SeekStart)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably sanity check to make sure this worked (i.e., we seeked the right amount).

@schomatis
Copy link
Contributor Author

Closed in favor of #60.

@schomatis schomatis closed this Jan 28, 2019
@ghost ghost removed the status/in-progress In progress label Jan 28, 2019
@schomatis schomatis deleted the feat/dag-reader/use-walker branch January 28, 2019 17:51
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants